package com.moxiao.yfjh.module.blind.dal.mysql.notifymessage;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.module.blind.controller.admin.notifymessage.vo.BlindNotifyMessageExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.notifymessage.vo.BlindNotifyMessagePageReqVO;
import com.moxiao.yfjh.module.blind.dal.dataobject.notifymessage.BlindNotifyMessageDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 相亲通知消息 Mapper
 *
 * @author mx
 */
@Mapper
public interface BlindNotifyMessageMapper extends BaseMapperX<BlindNotifyMessageDO> {

    default PageResult<BlindNotifyMessageDO> selectPage(BlindNotifyMessagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BlindNotifyMessageDO>()
                .eqIfPresent(BlindNotifyMessageDO::getMessageType, reqVO.getMessageType())
                .eqIfPresent(BlindNotifyMessageDO::getTitle, reqVO.getTitle())
                .eqIfPresent(BlindNotifyMessageDO::getImgurl, reqVO.getImgurl())
                .eqIfPresent(BlindNotifyMessageDO::getContent, reqVO.getContent())
                .eqIfPresent(BlindNotifyMessageDO::getJumpUrl, reqVO.getJumpUrl())
                .eqIfPresent(BlindNotifyMessageDO::getBussinessId, reqVO.getBussinessId())
                .eqIfPresent(BlindNotifyMessageDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BlindNotifyMessageDO::getReadStatus, reqVO.getReadStatus())
                .eqIfPresent(BlindNotifyMessageDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(BlindNotifyMessageDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BlindNotifyMessageDO::getId));
    }

    default List<BlindNotifyMessageDO> selectList(BlindNotifyMessageExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BlindNotifyMessageDO>()
                .eqIfPresent(BlindNotifyMessageDO::getMessageType, reqVO.getMessageType())
                .eqIfPresent(BlindNotifyMessageDO::getTitle, reqVO.getTitle())
                .eqIfPresent(BlindNotifyMessageDO::getImgurl, reqVO.getImgurl())
                .eqIfPresent(BlindNotifyMessageDO::getContent, reqVO.getContent())
                .eqIfPresent(BlindNotifyMessageDO::getJumpUrl, reqVO.getJumpUrl())
                .eqIfPresent(BlindNotifyMessageDO::getBussinessId, reqVO.getBussinessId())
                .eqIfPresent(BlindNotifyMessageDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BlindNotifyMessageDO::getReadStatus, reqVO.getReadStatus())
                .eqIfPresent(BlindNotifyMessageDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(BlindNotifyMessageDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BlindNotifyMessageDO::getId));
    }

    @Select("SELECT DISTINCT(message_type) FROM blind_notify_message WHERE deleted = 0")
    List<String> getMessageType();

    @Select("update blind_notify_message set read_status = 1 where user_id = #{userId}")
    void oneKeyClearNotifyMessage(@Param("userId") Long userId);
}
